<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<link rel="stylesheet" media="screen" type="text/css" href="__THEMES__/style/layout.css" />
		<script type="text/javascript" src="__JS__/jQuery/jquery.js"></script>
		<script type="text/javascript" src="__JS__/jQuery/plugin/jquery.filestyle.js"></script>
		<script type="text/javascript" src="__JS__/jQuery/plugin/troperate.js"></script>
		<script type="text/javascript" src="__JS__/jQuery/plugin/ajaxfileupload/ajaxfileupload.js"></script>
		<include file="Public:js_artDialog" />
		<script type="text/javascript">
			$(function(){
				$("input[type=file]").filestyle({ image : "__THEMES__/images/chk.png", imageheight : 25, imagewidth : 86, width : 260 });
			});
			function ajaxFileUpload(){
                if ($("#filedata").val() == ''){
                    setAlertBox('请选择要上传的文件！', 2);
                    return false;
                }else{
                    $.post("__APP__/Uploadfile/removefile",{
                    	file:"<?php if(isset($about['banner']) && !empty($about['banner'])){ echo $about['banner']; } ?>"
                    },function(data){
                    	if ( data.status == 1 ){
                    		$('#old_banner').remove();
                    	}
                    },'json');
                }
                //starting setting some animation when the ajax starts and completes
                $("#loading").ajaxStart(function(){ $(this).show(); }).ajaxComplete(function(){ $(this).hide(); });
        
                $.ajaxFileUpload({
                    url:'__APP__/uploadfile/upfile', 
                    secureuri:false,
                    fileElementId:'filedata',
                    dataType: 'json',
                    success: function (data, status){
                        //alert(data.msg.url);
                        if(typeof(data.error) != 'undefined'){
                            if(data.error != ''){
                                alert(data.error);
                            }else{
                                alert(data.msg);
                            }
                        }
                        $("#set_banner").after("<tr id='banner_display'><td></td><td align='left'><img src='"+data.msg.url+"' /><input type='hidden' name='banner' value='"+data.msg.url+"' /></td></tr>");
                        $("#buttonUpload").attr("disabled","disabled");
                        $("#filedata").attr("disabled","disabled");
                        $("#buttonUpload").after("&nbsp;&nbsp;<button class='attButton' id='removebanner' onclick=\"return removeFile(this,'"+data.msg.url+"');\">删除Banner</botton>");
                    },
                    error: function (data, status, e){
                        alert(e);
                    }
                });
                return false;
            }
            function removeFile(e,s){
				$.post("{:U('uploadfile/removefile')}",{
					file:s
				},function(data){
					if ( data.status == 1 ){
						$("#buttonUpload").removeAttr("disabled");
						$("#filedata").removeAttr("disabled");
						$("#banner_display").remove();
						$(e).remove();
					}
				},'json');
				return false;
			}
			function getCode(e){
				art.dialog.through({
					title : '获取代码',
					lock : true,
					content : '<textarea style="width:450px; height:140px;">&lt;script src=&quot;/adfree/getAD?item='+e+'&quot;&gt;&lt;/script&gt;</textarea>'
				});
			}
		</script>
		<style type="text/css">
			.form_table td	{ border:0; }
			.file_d_Upload	{ position: relative; height: 26px; display:block; }
			.attText		{ border: 1px solid #DDDDDD;font-family: verdana; font-size: 12px;padding: 4px!important;width: 460px; height:15px; }
			#buttonUpload	{ position:absolute; margin-left:96px; height:25px; padding:0 10px; cursor:pointer; vertical-align:middle; font-size:12px; word-break:keep-all;  white-space:nowrap; }
			#removebanner	{ position:absolute; margin-left:170px; height:25px; padding:0 10px; cursor:pointer; vertical-align:middle; font-size:12px; word-break:keep-all;  white-space:nowrap; }
		</style>
	</head>
	<body>
		
		<include file="Public:position" />
		
		<?php
		   if (!isset($_GET['type'])){
		       $type = 'index';
		   }else{
		       $type = $_GET['type'];
		   }
		?>
		
		<ul class="act_this">
    		<li<?php if(!isset($_GET['type'])){ ?> class="this"<?php } ?>><a href="{:U('index',array('tag'=>$_GET['tag']))}">首页轮换广告</a></li>
    		<li<?php if($_GET['type'] == 'about'){ ?> class="this"<?php } ?>><a href="{:U('index',array('tag'=>$_GET['tag'],'type'=>'about'))}">关于我们(首页)</a></li>
    		<li<?php if($_GET['type'] == 'allfree'){ ?> class="this"<?php } ?>><a href="{:U('index',array('tag'=>$_GET['tag'],'type'=>'allfree'))}">自由定制广告</a></li>
    	</ul>
    	
    	
    	    <?php
    	        if ($type != 'about'){
    	    ?>
    	    <div class="button" style="margin-top: 10px;">
            	<input type="button" value="新增广告" class="submit" id="add_index_banner" onclick="window.location.href='{:U('add?tag='.$_GET['tag'].'&type='.$type)}';"  />
            </div>
    	    <?php
    	        }
    	    ?>
        
                              
        <div class="a_table" style="position:relative;top:-1px;_top:-2px;">
    	<?php
    	    if ($type == 'about'){
    	?>
    	<form action="__URL__/aboutsave" method="post">
    	<input type="hidden" name="tag" value="{$_GET['tag']}" />
    	<input type="hidden" name="status" value="1" />
        <table width="100%" class="form_table">
        	<tr>
        		<td></td>
        		<td></td>
        	</tr>
            <tr>
                <td align="right">标题</td>
                <td><input type="text" name="title" class="input_text w480" value="{$about.title}" /></td>
            </tr>
            <tr>
                <td align="right">链接地址</td>
                <td><input type="text" name="url" class="input_text w480" value="{$about.url}" /></td>
            </tr>
            <tr id="old_banner">
                <td align="right">图片</td>
                <td><img src="{$about.banner}" /></td>
            </tr>
            <tr id="set_banner">
                <td align="right">上传图片</td>
                <td>
                    <span class="file_d_Upload">
                        <input id="filedata" type="file" class="attText" name="filedata">
                        <button class="attButton" id="buttonUpload" onclick="return ajaxFileUpload();">重新上传</button>
                    </span>
                </td>
            </tr>
            <tr style="display:none;" id="loading">
                <td></td>
                <td align='left'><img src="__THEMES__/images/loading.gif" /></td>
            </tr>
            <tr>
                <td align="right">内容</td>
                <td><textarea name="dsp" id="content" style="width: 70%; height:260px;">{$about.dsp}</textarea></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" class="submit" value="提交" /></td>
            </tr>
            <tr>
        		<td></td>
        		<td></td>
        	</tr>
        </table>
        </form>
    	<?php
    	    }else{
    	?>
    	<table width="100%">
            <tr style="background: #f0f7ff; font-weight: bold;">
                <td width="60" align="center" class="left_text">编号</td>
                <td align="center" class="left_text">标题名称</td>
                <td align="center" class="left_text">链接</td>
                <td width="100" align="center" class="left_text">状态</td>
                <td width="220" align="center" class="left_text">操作</td>
            </tr>
            <volist id="vo" name="list">
            <tr rel="{$vo['id']}" class="row_color"<?php if( ( $i % 2 ) == 0 ){ ?> bgcolor="#f9f9f9"<?php } ?>>
                <td align="center">{$vo['id']}</td>
                <td><a href="{:U('edit',array(
                    'id' => $vo['id'],
                    'tag' => $_GET['tag'],
                ))}">{$vo['title']}</a></td>
                <td align="center">{$vo['url']}</td>
                <td align="center">{$vo['status']|getStatus}</td>
                <td align="center">
                    <?php if($_GET['type'] == 'allfree'){ ?><a href="javascript:getCode('{$vo.id}');">获取代码</a><span class="action_line">|</span><?php } ?>{$vo['status']|showStatus=$vo['id']}<span class="action_line">|</span><a href="{:U('edit',array(
                    'id' => $vo['id'],
                    'tag' => $_GET['tag'],
                ))}" class="edit_model">编辑</a><span class="action_line">|</span><a href="{:U('delete',array(
                    'id' => $vo['id'],
                ))}" class="del_node" rel="{$vo.id}">删除</a>
                </td>
            </tr>
            </volist>
        </table>
        <div class="page">{$page}</div>
    	<?php
    	    }
    	?>
        </div>
	</body>
</html>